import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import { TopicView } from '../../model/topicView'

/**
 * Generated class for the MessagePopupPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@IonicPage()
@Component({
    selector: 'page-homePopup',
    templateUrl: 'homePopup.html',
})
export class HomePopupPage {

    action: any;
    topicView: TopicView;
    doFirst: boolean = true;

    constructor(public navCtrl: NavController, public navParams: NavParams) {
        this.action = navParams.data.callback;
        this.topicView = navParams.data.topicView;
    }

    topMessage() {
        // console.log('topMessage');
        this.ionViewWillLeave();
        this.action.topMessage(this.topicView.commuUserId);
        this.navCtrl.pop();
    }

    markMessage() {
        // console.log('markMessage');
        this.ionViewWillLeave();
        this.action.markMessage(this.topicView.commuUserId);
        this.navCtrl.pop();
    }

    deleteMessage() {
        // console.log('deleteMessage');
        this.ionViewWillLeave();
        this.action.deleteMessage(this.topicView.commuUserId);
        this.navCtrl.pop();
    }

    ionViewWillLeave(): void {
        // console.log('ionViewWillLeave');
        if(this.doFirst) {
            this.action.doNothing();
            this.doFirst = false;
        }
    } 

}
